package com.wangsh.splider.task.pojo;

import java.util.Date;
import java.util.Map;
import java.util.TreeMap;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.wangsh.splider.common.pojo.BasePojo;
import com.wangsh.splider.users.pojo.AAdmins;

/**
 * 任务描述表
 *
 * @author Songhy
 */
public class ATaskDesc extends BasePojo<ATaskDesc> {
    private int id;
    private int adminsId;
    private String name;
    private String contentParam ; 
    private String content;
    private byte status;
    private Date createTime;
    private Date updateTime;
    private Date pubTime;
    private String website;
    private int totalNum;
    private int succedNum;
    private int failedNum;
    private int viewNum;
    private int clickNum;

    /* 关联关系 */
    private AAdmins admins;
    
    /* json表示 */
    private JSONObject contentParamJSON ; 

    /*--字符串表示--*/
    private String statusStr;
    /* 存储所有状态的容器 */
    private Map<String, String> enumsMap = new TreeMap<String, String>();

    public Map<String, String> getEnumsMap() {
        // 根据状态值获取字符串描述
        ATaskDescEnum[] taskDescEnums = ATaskDescEnum.values();
        for (int i = 0; i < taskDescEnums.length; i++) {
            ATaskDescEnum taskDescEnum = taskDescEnums[i];
            String key = taskDescEnum.toString();
            if (key.lastIndexOf("_") != -1) {
                key = key.substring(0, key.lastIndexOf("_"));
            }
            enumsMap.put(key + "-" + taskDescEnum.getStatus() + "", taskDescEnum.getName());
        }
        return enumsMap;
    }

    public String getStatusStr() {
        // 根据状态值获取字符串描述
        ATaskDescEnum[] taskDescEnums = ATaskDescEnum.values();
        for (int i = 0; i < taskDescEnums.length; i++) {

            ATaskDescEnum taskDescEnum = taskDescEnums[i];

            if (taskDescEnum.toString().startsWith("STATUS_")) {

                // 表示是状态的标识
                if (taskDescEnum.getStatus() == this.getStatus()) {

                    this.statusStr = taskDescEnum.getName();
                    break;
                }
            }
        }
        return statusStr;
    }


    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public int getAdminsId() {
        return adminsId;
    }

    public void setAdminsId(int adminsId) {
        this.adminsId = adminsId;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getContent() {
        return content;
    }

    public void setContent(String content) {
        this.content = content;
    }

    public byte getStatus() {
        return status;
    }

    public void setStatus(byte status) {
        this.status = status;
    }

    public Date getCreateTime() {
        return createTime;
    }

    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }

    public Date getUpdateTime() {
        return updateTime;
    }

    public void setUpdateTime(Date updateTime) {
        this.updateTime = updateTime;
    }

    public Date getPubTime() {
        return pubTime;
    }

    public void setPubTime(Date pubTime) {
        this.pubTime = pubTime;
    }

    public AAdmins getAdmins() {
        return admins;
    }

    public void setAdmins(AAdmins admins) {
        this.admins = admins;
    }

    public String getWebsite() {
        return website;
    }

    public void setWebsite(String website) {
        this.website = website;
    }
    public int getTotalNum() {
        return totalNum;
    }

    public void setTotalNum(int totalNum) {
        this.totalNum = totalNum;
    }

    public int getSuccedNum() {
        return succedNum;
    }

    public void setSuccedNum(int succedNum) {
        this.succedNum = succedNum;
    }

    public int getFailedNum() {
        return failedNum;
    }

    public void setFailedNum(int failedNum) {
        this.failedNum = failedNum;
    }

    public int getViewNum() {
        return viewNum;
    }

    public void setViewNum(int viewNum) {
        this.viewNum = viewNum;
    }

    public int getClickNum() {
        return clickNum;
    }

    public void setClickNum(int clickNum) {
        this.clickNum = clickNum;
    }

	public String getContentParam()
	{
		return contentParam;
	}

	public void setContentParam(String contentParam)
	{
		this.contentParam = contentParam;
	}

	public JSONObject getContentParamJSON()
	{
		try
		{
			JSONObject resultJSON = (JSONObject) JSON.parse(this.contentParam);
			if(resultJSON == null)
			{
				return this.contentParamJSON ; 
			}
			return resultJSON ; 
		} catch (Exception e)
		{
		}
		return contentParamJSON;
	}
}
